//
//  TEEdgeInsetsViewController.m
//  TintExample
//
//  Created by Kevin Wu on 4/18/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import "TEEdgeInsetsViewController.h"



@implementation TEEdgeInsetsViewController

#pragma mark - UIViewController

- (void)loadView {
    [super loadView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self addButtonWithTitle:@"Title top" selector:@selector(titleTop:) type:1];
    [self addButtonWithTitle:@"Title left" selector:@selector(titleLeft:) type:1];
    [self addButtonWithTitle:@"Title bottom" selector:@selector(titleBottom:) type:1];
    [self addButtonWithTitle:@"Title right" selector:@selector(titleRight:) type:1];
    
    [self addButtonWithTitle:@"Image top" selector:@selector(imageTop:) type:2];
    [self addButtonWithTitle:@"Image left" selector:@selector(imageLeft:) type:2];
    [self addButtonWithTitle:@"Image bottom" selector:@selector(imageBottom:) type:2];
    [self addButtonWithTitle:@"Image right" selector:@selector(imageRight:) type:2];
    
    
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.frame = CGRectMake(10, 150, 300, 30);
    _titleLabel.textAlignment = UITextAlignmentCenter;
    [self.view addSubview:_titleLabel];
    
    _imageLabel = [[UILabel alloc] init];
    _imageLabel.frame = CGRectMake(10, 180, 300, 30);
    _imageLabel.textAlignment = UITextAlignmentCenter;
    [self.view addSubview:_imageLabel];
    
    
    
    _button = [[UIButton alloc] init];
    _button.backgroundColor = [UIColor lightGrayColor];
    _button.frame = CGRectMake(10, 220, 300, 180);
    _button.normalTitle = @"puppy";
    _button.normalImage = [UIImage imageNamed:@"box48.png"];
    _button.titleLabel.font = [UIFont systemFontOfSize:8.0];
    [self.view addSubview:_button];
    
    
    [self updateLabels];
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    for (UIView *v in _button.subviews) {
        [v showBorderWithRandomColor];
    }
}

- (void)titleTop:(id)sender {
    UIEdgeInsets ei = _button.titleEdgeInsets;
    ei.top = ei.top+1;
    _button.titleEdgeInsets = ei;
    [self updateLabels];
}
- (void)titleLeft:(id)sender {
    UIEdgeInsets ei = _button.titleEdgeInsets;
    ei.left = ei.left+1;
    _button.titleEdgeInsets = ei;
    [self updateLabels];
}
- (void)titleBottom:(id)sender {
    UIEdgeInsets ei = _button.titleEdgeInsets;
    ei.bottom = ei.bottom+1;
    _button.titleEdgeInsets = ei;
    [self updateLabels];
}
- (void)titleRight:(id)sender {
    UIEdgeInsets ei = _button.titleEdgeInsets;
    ei.right = ei.right+1;
    _button.titleEdgeInsets = ei;
    [self updateLabels];
}

- (void)imageTop:(id)sender {
    UIEdgeInsets ei = _button.imageEdgeInsets;
    ei.top = ei.top+1;
    _button.imageEdgeInsets = ei;
    [self updateLabels];
}
- (void)imageLeft:(id)sender {
    UIEdgeInsets ei = _button.imageEdgeInsets;
    ei.left = ei.left+1;
    _button.imageEdgeInsets = ei;
    [self updateLabels];
}
- (void)imageBottom:(id)sender {
    UIEdgeInsets ei = _button.imageEdgeInsets;
    ei.bottom = ei.bottom+1;
    _button.imageEdgeInsets = ei;
    [self updateLabels];
}
- (void)imageRight:(id)sender {
    UIEdgeInsets ei = _button.imageEdgeInsets;
    ei.right = ei.right+1;
    _button.imageEdgeInsets = ei;
    [self updateLabels];
}

- (void)updateLabels {
    _titleLabel.text = NSStringFromUIEdgeInsets(_button.titleEdgeInsets);
    _imageLabel.text = NSStringFromUIEdgeInsets(_button.imageEdgeInsets);
}

@end
